# 下载其他系统软件依赖安装包，需要wget
function DownloadSystemRequireInstallations() {
  local dataPath="${1}"
  local requirements="${2}"
  local releaServer="${3}"

  mkdir -p "${dataPath}" && cd "${dataPath}" 

  while IFS= read -r item; do
    yum -y remove "${item}*" &> /dev/null
    yum -y install "${item}" --downloadonly --downloaddir="${dataPath}" &> /dev/null
  done < "${requirements}"

  # # container-selinux
  # if [[ "${releaServer}x" == "x" ]];then
  #   return 1
  # elif [[ "${releaServer}" =~ "7.4".* ]];then
  #   # 7.4 => 2.36
  #   wget -q -N https://mirrors.aliyun.com/centos-vault/altarch/7.4.1708/extras/aarch64/Packages/container-selinux-2.36-1.gitff95335.el7.noarch.rpm?spm=a2c6h.13651111.0.0.34ca2f70DKVpi5&file=container-selinux-2.36-1.gitff95335.el7.noarch.rpm
  #   sleep 10s
  #   mv container-selinux-2.36-*.rpm* container-selinux-2.36-1.gitff95335.el7.noarch.rpm
  # elif [[ "${releaServer}" =~ "7.5".* ]];then
  #   # 7.5 => 2.66
  #   wget -q -N https://mirrors.aliyun.com/centos-vault/7.5.1804/extras/x86_64/Packages/container-selinux-2.66-1.el7.noarch.rpm?spm=a2c6h.13651111.0.0.34ca2f70DKVpi5&file=container-selinux-2.66-1.el7.noarch.rpm
  #   sleep 10s
  #   mv container-selinux-2.66-*.rpm* container-selinux-2.66-1.el7.noarch.rpm
  # elif [[ "${releaServer}" =~ "7.6".* ]];then
  #   # 7.6 => 2.74
  #   wget -q -N https://mirrors.aliyun.com/centos-vault/altarch/7.6.1810/extras/i386/Packages/container-selinux-2.74-1.el7.noarch.rpm?spm=a2c6h.13651111.0.0.34ca2f70DKVpi5&file=container-selinux-2.74-1.el7.noarch.rpm
  #   sleep 10s
  #   mv container-selinux-2.74-*.rpm* container-selinux-2.74-1.el7.noarch.rpm
  # else
  #   return 1
  # fi
}

# 下载Docker安装包，需要wget工具
function DownloadDockerInstallations() {
  local dataPath="${1}"
  local dockerRepo="${2}"

  mkdir -p "${dataPath}" && cd "${dataPath}"

  wget -q -O .index "${dockerRepo}"
  grep "^<a href=" .index | awk '{print $2}' |  awk -F '"' '{print $2}'  > .imageList
  while  IFS= read -r image; do
    wget -q -N "${dockerRepo}${image}"
  done < .imageList

  rm -f .index
  rm -f .imageList
}

